package com.intelligent.ispc.security;

import com.intelligent.ispc.core.dto.RoleDto;
import com.intelligent.ispc.core.dto.UserDto;
import com.intelligent.ispc.core.service.SecurityService;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.tags.PermissionTag;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by julia on 16/1/22.
 */
public class HasAnyPermissionTag extends PermissionTag {

    @Autowired
    protected SecurityService securityService;

    @Override
    protected boolean showTagBody(String permissions) {
        boolean hasAnyPermission = false;
        Subject subject = getSubject();
        if (subject != null) {
            for (String permission : permissions.split(",")) {
                if (subject.isPermitted(permission.trim())) {
                    hasAnyPermission = true;
                    break;
                }
            }
        }
        return hasAnyPermission;
    }
}
